<?php
namespace app\app\controller\v1;
use think\Db;
use app\app\util\OnlineUtils;
use app\app\util\CardUtils;
class MyCardController extends BaseController{


    /**
     * @return array
     *我的球星卡
     */
    public function showMyCard()
    {
        $user_id = OnlineUtils::getUserIdBySid();
        $my_card = Db::name('my_card')->alias('a')->join('card b','a.card_id=b.id','left')->field('a.id,a.num,a.card_id,b.name,concat("'.config('IMG_HEAD').'",b.img) img')->where('a.user_id','eq',$user_id)->select();
        foreach($my_card as $k => $v){
            if($v['num'] > 0){
                CardUtils::getUserStarCard($user_id,$v['card_id']);
            }
        }
        return ft(200,'success',$my_card);
    }

    //球星卡列表
    public function cardList()
    {
        $user_id = OnlineUtils::getUserIdBySid();
        $user = Db::name('user')->field('integral')->where('id','eq',$user_id)->find();
        $card = Db::name('card')->field('id,name,concat("'.config('IMG_HEAD').'",img) img,integral')->where('status','eq',1)->select();
        return ft(200,'success',['data'=>$card,'my_integral'=>$user['integral']]);
    }

}
